﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.eforceglobal.crux.views.Controls.Common;
using com.eforceglobal.crux.BusinessFacades;
using com.eforceglobal.crux.views.Enums;
using com.eforceglobal.crux.DTOs;
using com.eforceglobal.crux.security;

namespace com.eforceglobal.crux.controllers.Controls.Common
{
    public class ManagedEntityNameController
    {
        IManagedEntityName _view = null;
        public ManagedEntityNameController(IManagedEntityName view)
        {
            _view = view;
        }

        public void InitView(bool IsPostBack)
        {
            if (!IsPostBack)
            {
                ICruxSecurityManager securityManager = CruxSecurityManagerFactory.GetSecurityManager();
                LocationFacade locationFacade = new LocationFacade();
                if (_view.EntityType == EntityNameType.Company)
                    _view.EntityName = securityManager.GetCompany(_view.EntityID).CompanyName;
                else if (_view.EntityType == EntityNameType.Location)
                    _view.EntityName = locationFacade.GetLocation(_view.EntityID).LocationName;
            }
        }

        public void OpenEntityAdministrationView(int EntityID, EntityNameType EntityType)
        {
            if (EntityType == EntityNameType.Company)
                NavigationController.OpenView("ManageCompany", EntityID);
            else if (EntityType == EntityNameType.Location)
            {
                LocationFacade locationFacade = new LocationFacade();
                LocationInformation locationInformation = locationFacade.GetLocation(EntityID);
                NavigationController.OpenView("ManageLocations", locationInformation.CompanyID);
            }
        }
    }
}
